<?php
error_reporting(E_ALL ^ E_NOTICE);
include "../includes/global.php";
include "../includes/config.php";
//include "../includes/zipfileclass.php";
include "../lib/xtpl.php";
include "../classes/db.php";
include "../classes/gui.php";
include "../classes/upload.php";
include "FCKeditor/fckeditor.php";

////////////////
$DB = new DBCLASS();
$GUI = new GUI();
////////////////
$xtpl_main = new XTemplate("layout/layout.html");
////////////////
$mod = $_GET[mod];
$act = $_GET[act];
if($mod==''){
	$mod = "home";
}
if($act==''){
	$act = "index";
}
if(isset($_GET['lang'])){
    if($_GET['lang']=='vn'){
        $_SESSION['ID_LANG_ADM'] = 1;
    }
    elseif($_GET['lang']=='en'){
        $_SESSION['ID_LANG_ADM'] = 2;
    }
}
if(!isset($_SESSION['ID_LANG_ADM']) || $_SESSION['ID_LANG_ADM']==0){
    $_SESSION['ID_LANG_ADM'] = 1;
}
if($_SESSION['ID_LANG_ADM']==1){
    $xtpl_main->assign("languageVietnam",'selected="selected"');
}
else{
    $xtpl_main->assign("languageEnglish",'selected="selected"');
}
//--
$filename = "modules/{$mod}/{$act}.php";
//--
//-- 
$title_config = "SELECT * FROM {$DP}config ";
$rs_config = $DB->SQLexec($sql_config);
if($row_config = mysql_fetch_array($rs_config)){
	$xtpl_main->assign("title",$row_config['site_title']);
}
//--

if(file_exists($filename)){
	include $filename;
	@$xtpl->assign("site",$row_config);
}else{
	include "modules/home/index.php";
}

/************
/************
/************ List menu category
/************
/***********/

$catepath = $_GET[catepath];
if($catepath != ''){
	$catepath = explode("_",$catepath);
	$parent = $catepath[0];
	$cate_id = $catepath[1];
}
$sql_p = "SELECT * FROM {$DP}admin_cate WHERE parent_id=0 AND cate_id<>'67' ORDER BY cate_sort";
$rs_p = $DB->SQLexec($sql_p);
$count_p = 0;
$CountCateDiv = mysql_num_rows($rs_p);
while($row_p = mysql_fetch_array($rs_p)){
	$count_p++;
	//check count
	$sql_link = "SELECT * FROM {$DP}admin_cate WHERE parent_id=".$row_p[cate_id]." ORDER BY cate_sort ASC";
	$check_count = mysql_num_rows($DB->SQLexec($sql_link));
	//end
	$sql_c = "SELECT * FROM {$DP}admin_cate WHERE parent_id={$row_p[cate_id]} AND cate_act!='left_sub' ORDER BY cate_sort";
	$rs_c = $DB->SQLexec($sql_c);
	while($row_c = mysql_fetch_array($rs_c)){
		if($row_c[cate_id] == $cate_id)
			$row_c[cate_name] = '<span style="border-bottom:solid 1px #FFFFFF;font-style:italic">'.$row_c[cate_name].'</span';
		$row_c[cate_link] = '?mod='.$row_c[cate_mod].'&catepath='.$row_c[parent_id].'_'.$row_c[cate_id].'&act='.$row_c[cate_act].'&cid='.$row_c[cate_id];
		$xtpl_main->assign("block_sub_category",$row_c);
		$xtpl_main->parse("MAIN.mainbody.block_category.block_sub_category");
	}
	if($count_p < $CountCateDiv){
		$row_p[cate_break_item] = ',';
	}
	$row_p[CateDivDisplay] = 'none';	
	if($parent==$row_p['cate_id'] && $cate_id!=''){
		$row_p[CateDivDisplay] = 'block';
	}
	$xtpl_main->assign("CateDiv",$row_p);
	$xtpl_main->parse("MAIN.CateDiv");
	//check link
	if($check_count > 0){
		$check_link="javascript: _change_cate('_CateDiv_{block_category.cate_id}');";
		 $xtpl_main->assign("check_link",$check_link);
	}
	else{
		 $check_link="?mod=".$row_p['cate_mod']."&act=".$row_p['cate_act']."";
		 $xtpl_main->assign("check_link",$check_link);
	}
	$xtpl_main->assign("block_category",$row_p);
	$xtpl_main->parse("MAIN.mainbody.block_category");
}
$xtpl_main->assign("CountCateDiv",$CountCateDiv);
/************
/************
/************  Donot change the above unless you know what you are doing
/************
/***********/
$xtpl->parse("center");
$xtpl_main->assign("center_file",$xtpl->text("center"));
//--
$xtpl_main->assign("path_site",$base_url);
//--
if($_SESSION[ses_admin_id] != ''){
	$xtpl_main->parse("MAIN.mainbody");
}elseif($_SESSION[ses_admin_id] == ''){	
	$xtpl_main->parse("MAIN.login");
}
//--
$xtpl_main->parse("MAIN");
eval("?".">".$xtpl_main->text("MAIN"));
//$xtpl->out("MAIN");
?>

